import request from '@/utils/request'

/**
 * 角色接口
 * @method getPage 获取角色分页列表
 * @method getList 获取所有角色
 * @method save 保存角色
 * @method update 修改角色
 * @method remove 删除角色
 * @method getAuth 获取角色权限
 * @method saveAuth 保存角色权限
 */
export function useRoleApi() {
  const basePath = '/admin/role'

  const getPage = (params, data) => {
    return request({
      url: `${basePath}/page`,
      method: 'post',
      params,
      data
    })
  }

  const getList = () => {
    return request({
      url: `${basePath}/all`,
      method: 'get'
    })
  }

  const save = (data) => {
    return request({
      url: `${basePath}/save`,
      method: 'post',
      data
    })
  }

  const update = (data) => {
    return request({
      url: `${basePath}/update`,
      method: 'put',
      data
    })
  }

  const remove = (data) => {
    return request({
      url: `${basePath}/delete`,
      method: 'delete',
      data
    })
  }

  const getAuth = (id) => {
    return request({
      url: `${basePath}/get-auth/${id}`,
      method: 'get'
    })
  }

  const saveAuth = (data) => {
    return request({
      url: `${basePath}/save-auth`,
      method: 'post',
      data
    })
  }

  return {
    getPage,
    getList,
    save,
    update,
    remove,
    getAuth,
    saveAuth
  }
}
